#!/usr/bin/perl

#if(scalar @ARGV != 1)
#{
#	die("Usage: a.pl program");
#}

# Number of runs
$N = 100;
# Program to run
$PROG = "mono -O=-all,-peephole,-branch,-inline,-cfold,-consprop,-copyprop,-deadce,-linears,-cmov,-shared,-sched,-intrins,-tailc,-loop,-fcmov,-leaf,-aot,-precomp,-abcrem,-ssapre,-sse2 ".$ARGV[0]." matrix_transpose m.zip";

# Total time to run program runs
$total = 0.0;
for($i = 0;$i < $N;$i++)
{
	$output = `time -p $PROG 2>&1`;
	@split_output = split(/\n/,$output);
	foreach(@split_output)
	{
		if(/^real /)
		{
			@real_split = split(/ /,$_);
			$total += $real_split[1];
			print "Run: ",$i," Time: ",$real_split[1],"\n";
		}
	}
	`rm m.zip`
}
print "Average time (",$N," runs): ",$total/$N,"\n";
